package com.cskaoyan.service;

import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.po.MarketBrand;
import com.cskaoyan.bean.po.MarketBrandExample;
import com.cskaoyan.mapper.MarketBrandMapper;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wei
 * @since 2022/09/08 21:56
 */
@Service
public class WxBrandServiceImpl implements WxBrandService {
    @Autowired
    MarketBrandMapper brandMapper;

    @Override
    public CommonData queryBrandList(int page, int limit) {
        PageHelper.startPage(page,limit);//分页设置

        MarketBrandExample marketBrandExample = new MarketBrandExample();
        List<MarketBrand> marketBrands = brandMapper.selectByExample(marketBrandExample);
        int num  = marketBrands.size();
        int pages=num/limit+1;
        CommonData<MarketBrand> objectCommonData = new CommonData<>();
        objectCommonData.setLimit(limit);
        objectCommonData.setList(marketBrands);
        objectCommonData.setPages(pages);
        objectCommonData.setTotal(num);
        objectCommonData.setPage(page);
        return objectCommonData;
    }

    @Override
    public MarketBrand queryBrandDetail(Integer id) {
        MarketBrand marketBrand = brandMapper.selectByPrimaryKey(id);
        return marketBrand;
    }
}

